﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DTO;
using BUS;

namespace EXAM.Admin.A_ucontrol
{
    public partial class UsrLeftMenu : System.Web.UI.UserControl
    {
        String sErr = "";
        string _db = "EXA";
        int _Test = 1;
        int _Question = 2;       
        int _News = 3;
        int _Report = 4;
        int _AnalCode = 5;
        int _AnalDef = 6;
        int _Gadget = 7;
        int _File = 8;
        int _FileDel = 9;
        int _TestPage = 10;
        int _QnA = 11;
        int _User = 12;
        int _Group = 13;
        int _DataGroup = 14;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["UserAdmin"] != null)
                    SetPermission(Session["UserAdmin"] as DTO.UserInfo);
            }
        }

        private void SetPermission(UserInfo userInfo)
        {
            POPControl ctr = new POPControl();
            DTO.POPInfo inf = ctr.Get(userInfo.GroupCode, _db, ref sErr);
            if (inf.ROLE_ID != "")
            {
                string permis = GetPermission(inf, _Test);
                if (permis == "N")
                    linkTest.Visible = false;
                permis = GetPermission(inf, _AnalCode);
                if (permis == "N")
                    linkAnalysis.Visible = false;
                permis = GetPermission(inf, _AnalDef);
                if (permis == "N")
                    linkAnalDef.Visible = false;
                permis = GetPermission(inf, _File);
                if (permis == "N")
                    linkFile.Visible = false;
                permis = GetPermission(inf, _Gadget);
                if (permis == "N")
                    linkGadget.Visible = false;

                permis = GetPermission(inf, _Group);
                if (permis == "N")
                    linkGroup.Visible = false;
                permis = GetPermission(inf, _News);
                if (permis == "N")
                    linkNews.Visible = false;
                
                permis = GetPermission(inf, _QnA);
                if (permis == "N")
                    linkQnA.Visible = false;

                permis = GetPermission(inf, _Question);
                if (permis == "N")
                    linkQuestion.Visible = false;
                permis = GetPermission(inf, _Report);
                if (permis == "N")
                    linkReports.Visible = false;
                permis = GetPermission(inf, _TestPage);
                if (permis == "N")
                    linkTestPage.Visible = false;
                permis = GetPermission(inf, _User);
                if (permis == "N")
                    linkUser.Visible = false;
                permis = GetPermission(inf, _DataGroup);
                if (permis == "N")
                    linkDAOG.Visible = false;
            }
        }
        private string GetPermission(POPInfo user, int pos)
        {
            string permis = user.PERMISSION.Substring(pos - 1, 1);
            if (permis == " ")
                permis = user.DEFAULT_VALUE;
            return permis;
        }
        //public String LoadmenuNew()
        //{
        //    String kq = "";
        //    NewsCategoriesControl ctr = new NewsCategoriesControl();
        //    DataTable dt = ctr.GetAll_NewsCategories(ref sErr);
        //    foreach (DataRow row in dt.Rows)
        //    {
        //        String temp = "<li class=\"bg_list\">";
        //        NewsCategoriesInfo info = new NewsCategoriesInfo(row);
        //        temp += "<a href=\"/Admin/Page_Admin/NewSubCategories.aspx?IDCategoryNews=" + info.ID + "\">" + info.NameVN.ToUpperInvariant();
        //        temp += "</a></li>";
        //        kq += temp;
        //    }
        //    return kq;
        //}
    }
}